// 这份代码专门处理逻辑层的操作
const classesDao = require('../dao/classesDao');

const powerService = require('./powerService');

const classesService = {
    /*
     * 获取所有班级列表
     */
    async getAllClassesList() {
        let result;
        try {
            let selectResult = await classesDao.getAllClassesList();
            result = { success: true, msg: "查询成功", classList: selectResult }
        } catch (error) {
            result = { success: false, msg: "查询数据库时出错，查询失败" }
        }
        return result;
    },
    /*
     * 修改班级信息接口
     */
    async updateClasses(classId, className, gradeId, facultyId, level, teacherId, major) {
        let result;
        try {
            result = await classesDao.updateClasses(classId, className, gradeId, facultyId, level, teacherId, major);
            result = { success: true, msg: "修改成功" }
        } catch (error) {
            result = { success: false, msg: "操作数据库时出错，修改失败" }
        }
        return result;
    },
    /*
     * 删除班级信息接口
     */
    async delClasses(classId) {
        let result;
        try {
            result = await classesDao.delClasses(classId);
            result = { success: true, msg: "删除成功" }
        } catch (error) {
            result = { success: false, msg: "操作数据库时出错，删除失败" }
        }
        return result;
    },
    /*
     * 新增班级接口
     */
    async addClasses(className, gradeId, facultyId, level, teacherId, major) {
        let result;
        try {
            result = await classesDao.addClasses(className, gradeId, facultyId, level, teacherId, major);
            result = { success: true, msg: "新增成功", insertId: result.insertId }
        } catch (error) {
            result = { success: false, msg: "操作数据库时出错，新增失败" }
        }
        return result;
    },
    /*
     * 获取所有年级列表接口
     */
    async getAllGradeList() {
        let result;
        try {
            result = await classesDao.getAllGradeList();
            result = { success: true, msg: "查询成功", result }
        } catch (error) {
            result = { success: false, msg: "查询数据库时出错，查询失败" }
        }
        return result;
    }
};

module.exports = classesService;
